<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Proxy extends CI_Controller {
	var $remoteUrl = "";
	
	function __construct()
	{
		parent::__construct();
	}
	
	public function does($url){
		$this->remoteUrl = base64_decode($url);

		if (empty($this->remoteUrl)) die("代理地址错误");
		
		$method = $_SERVER['REQUEST_METHOD'];
		
		if ($method=="GET"){
			$this->_subget();
		}
		
		if ($method=="POST"){
			$this->_subpost();
		}
	}

	public function _subget()
	{
		echo file_get_contents($this->remoteUrl);
	}
	
	public function _subpost(){
		//echo $_POST['clients'];
		//print_r($this->input->post());
		//print_r($_POST);

		$data = http_build_query($_POST);
		//$data=file_get_contents('php://input');
		
		$opts = array (
		'http' => array (
			'method' => 'POST',
			'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
					   "Content-Length: " . strlen($data) . "\r\n",
			'content' => $data
		),
		);
		$context = stream_context_create($opts);
		$html = file_get_contents($this->remoteUrl , false, $context);
		echo $html;
	}
	

	
	
}

/* End of file proxy.php */
/* Location: ./application/controllers/proxy.php */